package com.ruoyi.reportReview.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.reportReview.domain.bo.ReportReviewBo;
import com.ruoyi.reportReview.domain.vo.IndustrialReportTotalInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.reportReview.domain.vo.IndustrialReportInfoVo;
import com.ruoyi.reportReview.domain.bo.IndustrialReportInfoBo;
import com.ruoyi.reportReview.service.IIndustrialReportInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 填报主表
 *
 * @author yangzhen
 * @date 2025-11-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/reportReview/reportInfo")
@Tag(name = "填报主表", description = "填报主表相关接口")
public class IndustrialReportInfoController extends BaseController {

    private final IIndustrialReportInfoService iIndustrialReportInfoService;

    /**
     * 查询填报主表列表
     */
    @Operation(summary = "查询填报主表列表", description = "用于查询填报主表列表")
    @SaCheckPermission("reportReview:reportInfo:list")
    @GetMapping("/list")
    public TableDataInfo<IndustrialReportInfoVo> list(IndustrialReportInfoBo bo, PageQuery pageQuery) {
        return iIndustrialReportInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出填报主表列表
     */
    @Operation(summary = "导出填报主表列表", description = "用于导出填报主表列表")
    @SaCheckPermission("reportReview:reportInfo:export")
    @Log(title = "填报主表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IndustrialReportInfoBo bo, HttpServletResponse response) {
        List<IndustrialReportInfoVo> list = iIndustrialReportInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "填报主表", IndustrialReportInfoVo.class, response);
    }

    /**
     * 获取填报主表详细信息
     *
     * @param id 主键
     */
    @Operation(summary = "获取填报主表详细信息", description = "用于获取填报主表详细信息")
    @SaCheckPermission("reportReview:reportInfo:query")
    @GetMapping("/{id}")
    public R<IndustrialReportInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iIndustrialReportInfoService.queryById(id));
    }


    @SaCheckPermission("reportReview:reportInfo:query")
    @GetMapping("/getReportInfoById/{id}")
    public R<IndustrialReportTotalInfoVo> getReportInfoById(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iIndustrialReportInfoService.getReportInfoById(id));
    }

    /**
     * 新增填报主表
     */
    @Operation(summary = "新增填报主表", description = "用于新增填报主表")
    @SaCheckPermission("reportReview:reportInfo:add")
    @Log(title = "填报主表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IndustrialReportInfoBo bo) {
        return toAjax(iIndustrialReportInfoService.insertByBo(bo));
    }

    /**
     * 修改填报主表
     */
    @Operation(summary = "修改填报主表", description = "用于修改填报主表")
    @SaCheckPermission("reportReview:reportInfo:edit")
    @Log(title = "填报主表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IndustrialReportInfoBo bo) {
        return toAjax(iIndustrialReportInfoService.updateByBo(bo));
    }

    /**
     * 删除填报主表
     *
     * @param ids 主键串
     */
    @Operation(summary = "删除填报主表", description = "用于删除填报主表")
    @SaCheckPermission("reportReview:reportInfo:remove")
    @Log(title = "填报主表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iIndustrialReportInfoService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 审核填报主表
     */
    @Operation(summary = "审核填报主表", description = "用于审核填报主表")
    @Log(title = "填报主表审核", businessType = BusinessType.UPDATE)
    @PostMapping("/review")
    public R<Void> review(@Validated @RequestBody ReportReviewBo bo) {
        return toAjax(iIndustrialReportInfoService.review(bo));
    }

}
